package com.huang.unsafe;

import java.util.concurrent.TimeUnit;
/*
*   volatile 保证可见性 可让线程中途读取
* */
public class testVolatile {
    private volatile static int num=0;
    public static void main(String[] args) {


        new Thread(()->{
            while (num==0){

            }
        },"A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        num=1;
        System.out.println(num);
    }
}
